package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//区域控制器
@Controller
@RequestMapping("destination")
public class DestinationController {
    //注入目的地业务
    @Autowired
    private IDestinationService destinationService;

    //分页查询
    @RequestMapping("/list")
    public String list(Model model , @ModelAttribute("qo") DestinationQuery qo){
        //Page是spring-data-mongodb 里封装分页参数的对象.类似pegeinfo
        Page<Destination> page = destinationService.list(qo);
        model.addAttribute("page" , page);

        //导航toasts查询
        model.addAttribute("toasts", destinationService.getToasts(qo.getParentId()));

        return "destination/list";
    }


    //目的地简介修改
    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object updateInfo(String id , String info){
        destinationService.updateInfo(id , info);

        return JsonResult.success();
    }
}
